package nveces.jspwiki.plugins.svg;

import static nveces.jspwiki.plugins.svg.MagicNamesPluginSvg.CONTENT_TYPE_IMAGE_JPEG;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

/**
 * $Id: SvgImageServlet.java 10 2011-02-26 20:48:09Z nveces@gmail.com $
 * @author nveces
 *
 */
public class SvgImageServlet extends HttpServlet {


    private static final Logger log = Logger.getLogger(SvgImageServlet.class);
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        HttpSession session = request.getSession(true);
        String id = request.getParameter("id");
        String filename = (String)session.getAttribute(id);
        log.info("doGet()--->FileName: "+filename);
        //byte[] body = (byte[]) session.getAttribute(id);
        response.setContentType(CONTENT_TYPE_IMAGE_JPEG);
        /**
         * response.setHeader("Cache-Control","no-cache");
         * response.setHeader("Pragma","no-cache");
         * response.setDateHeader("Expires", 0);
         */
        OutputStream out = response.getOutputStream();
        //out.write(body);
        out.flush();
        out.close();
        session.removeAttribute(id);
    }
}
